<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>用户列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片视图 -->
        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容">
                        <el-button slot="append" icon="el-icon-search" v-model="queryInfo.query"></el-button>
                    </el-input>
                </el-col>
            </el-row>

            <!-- 订单列表数据 -->
            <el-table :data="DataList" border stripe>

                <!-- 序号 -->
                <el-table-column type="index"></el-table-column>

                <!-- 订单编号 -->
                <el-table-column label="订单编号" prop="order_number"></el-table-column>

                <!-- 订单价格 -->
                <el-table-column label="订单价格" prop="order_price"></el-table-column>

                <!-- 是否付款 -->
                <el-table-column label="是否付款" prop="pay_status">
                    <template v-slot="scope">
                        <el-tag type="success" v-if="scope.row.pay_status == 1">已付款</el-tag>
                        <el-tag type="danger" v-else-if="scope.row.pay_status == 0">未付款</el-tag>
                    </template>
                </el-table-column>

                <!-- 是否发货 -->
                <el-table-column label="是否发货" prop="is_send"></el-table-column>

                <!-- 下单时间 -->
                <el-table-column label="下单时间">
                    <template v-slot="scope">
                        {{scope.row.create_time | dateFormat}}
                    </template>
                </el-table-column>

                <!-- 操作 -->
                <el-table-column label="操作" prop="order_time">
                    <template v-solt="scope">
                        <el-button type="primary" icon="el-icon-edit" @click="showbox" size="mini"></el-button>
                        <el-button type="success" icon="el-icon-location" @click="showProBox" size="mini"></el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页区域 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum"
                :page-sizes="[1, 5, 8, 10]"
                :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>

            <!-- 修改对话框 -->
            <el-dialog
                title="修改地址"
                :visible.sync="dialogVisible"
                width="50%"
                @close="Closed"
            >
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                    <el-form-item label="省市区/县" prop="address1">
                            <el-cascader
                                :options="options"
                                v-model="ruleForm.address1"
                                @change="handleChange"
                            >
                            </el-cascader>
                    </el-form-item>
                    <el-form-item label="详细地址" prop="address2">
                        <el-input v-model="ruleForm.address2"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
                </span>
            </el-dialog>

            <!-- 修改对话框 -->
            <el-dialog
                title="修改地址"
                :visible.sync="logVisible"
                width="50%"
            >

                <span>物流接口无法使用！</span>

                <span slot="footer" class="dialog-footer">
                    <el-button @click="logVisible = false">取 消</el-button>
                    <el-button type="primary" @click="logVisible = false">确 定</el-button>
                </span>
            </el-dialog>
        </el-card>
    </div>
</template>
<script>

import { provinceAndCityData, CodeToText } from 'element-china-area-data'

export default {
    data() {
        return {
            queryInfo:{
                query:'',
                pagenum:1,
                pagesize:10
            },
            total:0,
            DataList:[],
            dialogVisible:false,
            ruleForm:{
                address1:[],
                address2:''
            },
            rules:{
                address1:[
                    { required: true, message: '请请选择省市区/县', trigger: 'blur' }
                ],
                address2:[
                    { required: true, message: '请填写详细地址', trigger: 'blur' }
                ]
            },
            options: provinceAndCityData,
            logVisible:false
        }
    },
    methods:{

        //获取订单数据列表
        async getOrderList(){
            const { data } = await this.axios.get('orders',{params:this.queryInfo})
            
            this.total = data.data.total
            this.DataList = data.data.goods
            //console.log(data)
        },
        handleSizeChange(size){
            this.queryInfo.pagesize = size;
            this.getOrderList()
        },
        handleCurrentChange(page){
            this.queryInfo.pagenum = page;
            this.getOrderList()
        },
        
        //修改对话框
        showbox(){
            this.dialogVisible = true
        },
        handleChange(value){
            if (value[1] != null && value[2] != null) {
                var dz = CodeToText[value[0]] + '/' + CodeToText[value[1]] + '/' + CodeToText[value[2]]
                this.addressid = value[2]
            } else {
                if (value[1] != null) {
                    dz = CodeToText[value[0]] + '/' + CodeToText[value[1]]
                    this.addressid = value[1]
                } else {
                    dz = CodeToText[value[0]]
                    this.addressid = value[0]
                }
            }
                this.address = dz
                //console.log(dz)
                //console.log(value)
        },

        //关闭重置
        Closed(){
            this.$refs.ruleForm.resetFields()
        },

        //展示物流进度对话框
        async showProBox(){

            this.logVisible = true
        }
    },
    created() {
        this.getOrderList()
    },
}
</script>
<style lang="less" scoped>

    .el-table{
        margin: 12px 0;
    }
    .el-cascader{
        width: 100%;
    }
</style>